/**
 * Writed by yura and mak
 */

package wz.legend.handlers;


import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;

import org.apache.log4j.Logger;

import wz.legend.Context;
import wz.legend.HttpContext;

/**
 * User: yura
 */
public class StopHandler implements ResponseHandler{
    private static final Logger LOG = Logger.getLogger(StopHandler.class);

    private Date stopDate;
    private DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    public void handle(HttpContext httpContext, Context context) {
        if (stopDate != null && stopDate.before(new Date())) {
            System.exit(0);   
        }
    }

    public Date getStopDate() {
        return stopDate;
    }

    public void setStopDate(Date stopDate) {
        this.stopDate = stopDate;
    }

    public String getStopDateString() {
        return format.format(stopDate);
    }

    public void setStopDateString(String stopDate) {
        try {
            this.stopDate = format.parse(stopDate);
        } catch (ParseException e) {
            LOG.error(e, e);
            throw new RuntimeException(e);
        }
    }
}
